<?php
include('includes/header.php');
$month = $_GET['month'];
$year = $_GET['year'];

if ($month == "01") $previous = "/" . ($year - 1) . "/12/";
else $previous = "/$year/" . make_two($month - 1) . "/";

if ($month == "12") $next = "/" . ($year + 1) . "/01/";
else $next = "/$year/" . make_two($month + 1) . "/";

?>
<div class='previous'><a href='/calendar<?php echo $previous; ?>'>&laquo;</a></div>

<?php if ($month != date('m') | $year != date('Y')) { ?>
<div class='current'> [ <a href='/calendar/<?php echo date('Y'); ?>/<?php echo date('m'); ?>/'>Jump to Current Month</a> ] </div>
<? } else { ?>
<div class='top-nav'>[ <a href='/calendar/subscribe/'>Subscribe</a> | <a href='/calendar/add/'>Add An Event</a> | <a href='http://www.twitter.com/ColonialCal/' target='_blank'>Follow on Twitter</a> | <a href='/calendar/submit/'>Submit A Calendar</a> <?php if (is_admin($_SESSION['UserID']) && sizeof(get_pending_events())>0 | sizeof(get_pending_feeds()) > 0) echo "| <a href='/calendar/pending.php'>Pending Moderation</a>"; ?>]</div>
<?php } ?>
<div class='next'><a href='/calendar<?php echo $next; ?>'>&raquo;</a></div>
<div class='clear'> </div> 
<table class='month' border='1'>	
		<caption><?php echo date("F Y",strtotime("$year-$month-01")); ?></caption>
	<tr>
		<th>Sunday</th>	
		<th>Monday</th>
		<th>Tuesday</th>
		<th>Wednesday</th>
		<th>Thursday</th>
		<th>Friday</th>
		<th>Saturday</th>	
	</tr>
	<tr>
<?php for ( $i = 1; $i < get_first_day($month, $year); $i++) { ?>
	<td class='empty'> &nbsp </td>
<? } ?>
<?php for ( $i = 1; $i <= get_days($month, $year); $i++) { ?>
	<?php $events = get_events($i,$month,$year);  ?>
	<td class='day<?php if (sizeof($events)>0) echo " events"; ?><?php if (date('m')==$month && date('d')==$i) echo " today"; ?><?php if (get_day_of_week($i,$month,$year) == 7 | get_day_of_week($i,$month,$year) == 1) echo " weekend"; else echo " weekday"; ?>'>
		<div class='date'><a href='<?php echo make_two($i);?>/'><?php echo $i; ?></a></div> 
		<div class='clear'> </div>
		<?php if (sizeof($events)>0) { ?>
		<div class='events'>
		<ul>
			<?php 
			foreach ($events as $event) { 
			$date = str_replace("-","/",$event['startdate']);
			?>
					<li><?php if (should_display_time($event,$year,$month,$i)) { ?>
						<span class='time'>
						<?php echo format_time($event['starttime']); ?></span>:
						<?php } ?>
				
					<a href='/calendar/<?php echo $date . "/" . $event['slug']; ?>/?height=300&width=450' title='<?php echo $event['title']; ?>' class="thickbox" >
					<span class='title'>
						<?php echo $event['title']; ?>
					</span></a>
					</li>
			<?php
			}
			?>
		</ul>
		</div>
		<?php } ?>
	</td>
	<?php if (get_day_of_week($i,$month,$year) == 7) { ?>
	</tr>
	<tr>
	<?php } ?>
<? } ?>
	<?php for ($x = get_day_of_week($i-1, $month, $year); $x < 7; $x++) { ?>
	<td class='empty'> &nbsp </td>
	<? } ?>
	</tr>
</table>
<div class='plug'>
Don't see your event here?  Be sure to <a href='/calendar/add/'>add it</a>.
</div>
<div class='clear'> </div>
<?php
include('includes/footer.php');
?>